#include "statusWidget.h"

statusWidget::statusWidget(QWidget *parent): QWidget(parent){

	activeObject = 0;
	timer = new QTimer(this);
	layout = new QHBoxLayout();
	layout->setContentsMargins(2, 2, 0, 0);
	setLayout(layout);
	createLabels();
	
	connect(timer, SIGNAL(timeout()), this, SLOT(removeMessage()));

}

void statusWidget::removeMessage(){
	
	QString string;

	messageLabel->setText(string);

}

void statusWidget::clearAll(){

	QString string;
	
	messageLabel->setText(string);
	activeObjectLabel->setText(string);
	scaleLabel->setText(string);
	coordsLabel->setText(string);

}

void statusWidget::showMessage(QString message, int duration){

	timer->start(duration);
	messageLabel->setText(message);

}

void statusWidget::setActiveObject(gObject *object){
	
	QString string(tr("Aktivní objekt: %1"));
	
	
	if(object){ 
		QString name(object->getName().c_str());
		activeObjectLabel->setText(string.arg(name));
	}
	else
		activeObjectLabel->setText(string.arg(tr("žádný")));

}

void statusWidget::setCoords(QPointF &point){

	QString string(tr("Souřadnice: (%1, %2)").arg(point.x()).arg(point.y()));
	
	coordsLabel->setText(string);

}

void statusWidget::setScale(float sc){

	QString string(tr("Měřítko: 1:%1").arg(sc));
	
	scaleLabel->setText(string);

}

void statusWidget::createLabels(){

	messageLabel = new QLabel;
	messageLabel->setMinimumSize(400, 0);
	layout->addWidget(messageLabel);

	coordsLabel = new QLabel;
	coordsLabel->setMinimumSize(200, 0);
	layout->addWidget(coordsLabel);
	
	scaleLabel = new QLabel;
	scaleLabel->setMinimumSize(100, 0);
	layout->addWidget(scaleLabel);
	
	activeObjectLabel = new QLabel;
	activeObjectLabel->setMinimumSize(150, 0);
	layout->addWidget(activeObjectLabel);

}
